{% extends 'base.html' %}
{% load catalog_extras %}

{% block extra_style %}
{% load static %}
<link rel="stylesheet" href="{% get_static_prefix %}css/catalogs.css" type="text/css" media="all" />
{% endblock extra_style %}

{% block java_script %}
{% load static %}
<script type='text/javascript'
    src='{% get_static_prefix %}js/catalogs.js'>
</script>
{% endblock java_script %}

{% block content %}
<div class="row-fluid">
  <div class="span4">
    {% if catalog_name %}
        {% if catalog %}
          <div class='well'>
        <strong>Catalog:
        <span class='dropdown'>
          <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
            {{ catalog_name }} <b class="caret"></b>
          </a>
          <ul class="dropdown-menu">
            {% for item in catalog_list %}
              <li><a href="/catalog/{{ item }}">{{ item }}</a></li>
            {% endfor %}
          </ul>
        </span></strong>
        </div>
            <table class="table table-striped table-condensed wraptext" id='catalog_items'>
              <thead>
                <tr><th>Name</th><th>Version</th></tr>
              </thead>
              <tbody>
              {% regroup catalog|dictsort:'name' by name as catalog_items %}
                {% for item_name in catalog_items %}
                  <tr class='catalog_item' name='{{ item_name.grouper }}'>
                  <td class='xlabel'>
                  {% with item_name.list|dictsortreversed:'version' as item_list %}
                    <a href='#' onClick="getCatalogItem('{{ catalog_name }}', '{{ item_list.0.index }}', '{{ item_name.grouper }}', '{{ item_list.0.version }}')">
                  {% endwith %}
                    {{ item_name.grouper|wrappable }}</a>
                  </td>
                  <td class='version'>
                    <ul class='list'>
                      {% for item in item_name.list|dictsortreversed:'version' %}
                        {% if forloop.counter0 == 0 %}
                          <li><a href='#' onClick="getCatalogItem('{{ catalog_name }}', '{{ item.index }}', '{{ item_name.grouper }}', '{{ item.version }}')">
                            {{ item.version|wrappable }}</a>
                          </li>
                         {% else %}
                          <li class='listborder'><a href='#' onClick="getCatalogItem('{{ catalog_name }}', '{{ item.index }}', '{{ item_name.grouper }}', '{{ item.version }}')">
                            {{ item.version|wrappable }}</a>
                          </li>
                         {% endif %}
                      {% endfor %}
                    </ul>
                  </td>
                  </tr>
                {% endfor %}
              </tbody>
          </table>
        {% else %}
          <p>Catalog {{ catalog_name }} is empty.</p>
        {% endif %}
    {% endif %}
  </div>
  <div class='span8'>
    <div id="catalog_item_detail"></div>
  </div>
</div>
{% endblock content %}
